#include <REGX52.H>
#include <intrins.h>


void Key_Delay(unsigned char n) //@11.0592MHz
{
	while (n)
	{
		unsigned char i, j;

		_nop_();
		_nop_();
		_nop_();
		i = 11;
		j = 190;
		do
		{
			while (--j)
				;
		} while (--i);
		n--;
	}
}


unsigned char key()
{
	unsigned char Key_Count=0;
	if(P3_1==0){Key_Delay(20);while(P3_1==0);Key_Delay(20);Key_Count=1;}
	if(P3_0==0){Key_Delay(20);while(P3_0==0);Key_Delay(20);Key_Count=2;}
	if(P3_2==0){Key_Delay(20);while(P3_2==0);Key_Delay(20);Key_Count=3;}
	if(P3_3==0){Key_Delay(20);while(P3_3==0);Key_Delay(20);Key_Count=4;}
	return Key_Count;
	
}